package com.example.demo.moduel.service;

import com.example.demo.moduel.entity.Student;
import com.example.demo.moduel.mapper.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
/*为了返回一个UserDetailsService给配置config*/
public class StudentService implements UserDetailsService{
       @Autowired
       private StudentRepository studentRepository;
       @Override
       public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
              Student student=studentRepository.findByUsername(s);
              if (student == null) {
                     throw new UsernameNotFoundException("用户名不存在");
              }
              System.out.println("s:"+s);
              System.out.println("username:"+student.getUsername()+";password:"+student.getPassword());
              return student;
       }
}
